import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:part_time_job_pro/common/services/storage.dart';
import 'package:part_time_job_pro/common/store/config.dart';
import 'package:part_time_job_pro/common/utils/loading.dart';

import 'common/widgets/custom_animation.dart';

/// 全局静态数据
class Global {

  /// 初始化
  static Future init() async {
    // 初始化flutter
    WidgetsFlutterBinding.ensureInitialized();

    await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);

    ///初始化状态栏
    setSystemUiStype();
    Loading();

    ///初始化sevice
    await Get.putAsync<StorageService>(() => StorageService().init());

    //hive持久化初始化
    await Hive.initFlutter();
    await Hive.openBox('appBox');

    /// 初始化存储
    Get.put<ConfigStore>(ConfigStore());

    //初始化loading组件
    configLoading();
  }

  static void setSystemUiStype() {
    if (GetPlatform.isAndroid) {
      SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarBrightness: Brightness.light,
        statusBarIconBrightness: Brightness.dark,
        systemNavigationBarDividerColor: Colors.transparent,
        systemNavigationBarColor: Colors.white,
        systemNavigationBarIconBrightness: Brightness.dark,
      );
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }
  }


 static void configLoading() {
    EasyLoading.instance
      ..displayDuration = const Duration(milliseconds: 1500)
      ..indicatorType = EasyLoadingIndicatorType.fadingCircle
      ..loadingStyle = EasyLoadingStyle.dark
      ..indicatorSize = 35.0
      ..radius = 10
      ..progressColor = Colors.yellow
      ..backgroundColor = Colors.green
      ..indicatorColor = Colors.yellow
      ..textColor = Colors.yellow
      ..textPadding = const EdgeInsets.all(10.0)
      ..textStyle = const TextStyle(fontSize: 14,color: Colors.white)
      ..maskColor = Colors.black.withOpacity(0.25)
      ..userInteractions = false
      ..dismissOnTap = false
      ..customAnimation = CustomAnimation();
  }

}
